feat(world-builder): NPC placement, movement, and map persistence API (Closes #8) - #218
feat(world-builder): NPC placement, movement, and map persistence API (Closes #8)#218Rodrigoue9 wants to merge 5 commits into
Conversation
…r and isValidGameNpcIndex, tighten mapNum validation (Bitcoindefi#8)
Code Review ✅ Approved 4 resolved / 4 findingsImplements Stage 2 World Builder API for NPC placement, movement, removal, and persistence on game maps with full CRUD endpoints and validation. Fixed config initialization, exported missing utilities, added concurrency mutex to prevent race conditions on concurrent writes, and tightened mapNum validation to reject values ≤ 0. ✅ 4 resolved✅ Bug: config.mapsSourceDir does not exist on Config
✅ Bug: isValidGameNpcIndex not exported from gameNpcs
✅ Bug: Concurrent NPC writes lose updates (read-modify-write race)
✅ Edge Case: move/delete endpoints accept mapNum <= 0
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Important Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |
|
¡Hola @leocagli! Espero que hayas tenido un excelente inicio de semana. Te comento que el PR #218 (
Quedo totalmente a tu disposición por si requieres algún ajuste adicional, o si ya podemos proceder con la revisión final y merge de esta etapa para cerrar el milestone. ¡Muchas gracias! 🙌 |
Summary
Implements the Stage 2 World Builder API for placing, moving, removing, and listing NPCs on game maps with robust validation and persistence, as specified and assigned in #8.
Closes #8
Changes
api/src/lib/mapNpcStorage.ts:MAX_NPCS_PER_MAP = 50as an exported, single-source named constant.placeMapNpcwith coordinate boundary (1-100), catalog validity (isValidNpcIndex), blocked tile check (isTileBlocked), duplicate placement rejection, and map quota enforcement.moveMapNpcsupporting smooth destination updates while handling self-tile in-place repositioning (fromX === toX && fromY === toY) without spurious collision errors.removeMapNpcfor atomic NPC deletion and disk synchronization.api/src/mapas_source/mapa_<n>/npcs.json.api/src/server.ts:/admin/game-data/maps/:mapNum/npcs:GET /admin/game-data/maps/:mapNum/npcs-> lists placed NPCsPOST /admin/game-data/maps/:mapNum/npcs-> places NPCPUT /admin/game-data/maps/:mapNum/npcs/move-> moves NPCDELETE /admin/game-data/maps/:mapNum/npcs/:x/:y-> removes NPCapi/src/tests/mapNpcPlacement.test.ts:Verification